// https://leetcode.cn/problems/positions-of-large-groups/
// Created by ade on 2022/8/17.
//
#include <iostream>
#include <vector>
#include <string>


using namespace std;

class Solution {
public:
    vector <vector<int>> largeGroupPositions1(string s) {
        int left = 0, right = 1;
        vector <vector<int>> res = {};
        while (right < s.size()) {
            if (s[left] != s[right]) {
                left = right;
                right++;
            } else {
                while (right < s.size() - 1 && s[right] == s[right + 1]) {
                    right++;
                }
                if (right - left >= 2) {
                    res.push_back({left, right});
                }
                left = right + 1;
                right += 2;
            }
        }
        return res;
    }

    vector <vector<int>> largeGroupPositions(string s) {
        vector <vector<int>> res = {};
        int num = 1;
        for (int i = 0; i < s.size(); i++) {
            if (i == s.size() - 1 || s[i] != s[i + 1]) {
                if (num >= 3) {
                    res.push_back({i - num + 1, i});
                }
                num = 1;
            } else {
                num++;
            }
        }
        return res;
    }
};

int main() {
    Solution so;
    string s = "aaa";
    auto res = so.largeGroupPositions(s);
    for (auto i : res) {
        for (auto j : i) {
            cout << j << ",";
        }
        cout << endl;
    }

    return 0;
}